<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>

<?php
require 'connect.inc';
require 'session.inc';
$type = $_REQUEST["type"];
$key = $_REQUEST["key"];
$flag = FALSE;
if($key =="")
    return;
$res = "";
$name = "";
switch ($type) {
    case 1: // check user name register
        $strSQL = "SELECT * FROM users WHERE user_name ='$key'";
        $name = "User name";
        break;
    case 2:// check ablum name 
        $strSQL = "SELECT * FROM album WHERE album_name ='$key'";
        $name = "Album name";
        break;
    case 3:// check photo name 
        $strSQL = "SELECT * FROM photo WHERE photo_name ='$key'";
        $name = "Photo name";
        break;
    case 4:// search photo 
        $strSQL = "SELECT * FROM photo WHERE photo_name like '$key%'";
        break;
   
}
//echo $strSQL;
$result = mysql_query($strSQL);
if ($type == 4  ) {
    if($result && mysql_num_rows($result) > 0)
    while ($row = mysql_fetch_array($result)) {
        $res .= $row["photo_name"] . ", ";
    }
    else $res.= "No suggestion.";
} else
if ($result && mysql_num_rows($result) > 0) {
    $res .= "* $name already exist.";
} else {
    $res .= "* $name available.";
    $flag = true;
}
echo $flag;
?>
   